package logic

import (
	"2210a/practice/pkg"
	"2210a/practice/practiceapi/internal/svc"
	"2210a/practice/practiceapi/internal/types"
	"2210a/practice/practicerpc/practicerpc"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShopAddLogic) ShopAdd(req *types.ShopAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.PracticeRpc.ShopAdd(l.ctx, &practicerpc.ShopAddRequest{
		UserId:         req.UserId,
		Avatar:         req.Avatar,
		ShopName:       req.ShopName,
		ShopNavigation: req.ShopNavigation,
		ShopLabel:      req.ShopLabel,
		ShopBank:       req.ShopBank,
		SalesVolume:    req.SalesVolume,
		Status:         req.Status,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品添加成功",
		Data:    add.Id,
	}, nil
}
